<?php

namespace App\Models\Api;

use Illuminate\Database\Eloquent\Model;

class AdminUser extends Model
{

    protected $table = 'admin_user';
    protected $primaryKey = 'id';
    protected $dateFormat = 'U';// 时间戳
    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s'
    ];

    /**
     * 获取信息
     * @param $param
     * @return mixed
     */
    public static function getInfo($param)
    {
        $where = Array();
        if (isset($param['username']) && !empty($param['username'])) {
            $where[] = ['username', '=', $param['username']];
        }
        if (isset($param['mobile']) && !empty($param['mobile'])) {
            $where[] = ['mobile', '=', $param['mobile']];
        }

        $info = self::where($where)->first();
        return $info;
    }

    /**
     * 编辑管理员
     * @param $id
     * @param $info
     * @return mixed
     */
    public static function editAdmin($id, $info)
    {
        $info['updated_at'] = time();

        return self::where(['id' => $id])->update($info);
    }
}
